package com.tm.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created by lichuan on 2022-09-05.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private int code ;

    private String msg;

    private T data;


    public static Result SUCCESS(Object data,ResultCode resultCode){

        return new Result(resultCode.getCode(),resultCode.getMsg(),data);
    }

    public static Result SUCCESS(ResultCode resultCode){

        return SUCCESS(null,resultCode);
    }

    public static Result SUCCESS(){

        return SUCCESS(null,ResultCode.SUCCESS);
    }

    public static Result SUCCESS(Object data){

        return SUCCESS(data,ResultCode.SUCCESS);
    }

    public static Result error(Integer errorCode, String errorMessage) {
        return new Result(errorCode,errorMessage,null);
    }

    public static Result error() {
        return new Result(ResultCode.FAIL.getCode(),ResultCode.FAIL.getMsg(),null);
    }
    public static Result error(ResultCode resultCode) {
        return new Result(resultCode.getCode(),resultCode.getMsg(),null);
    }
}
